<HTML>
<HEAD>
<TITLE>[Chapter 13] AWT Exceptions and Errors</TITLE>
<META NAME="author" CONTENT="John Zukowski">
<META NAME="date" CONTENT="Thu Jul 31 14:52:27 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java AWT">
<META NAME="title" CONTENT="Java AWT">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java AWT" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch12_05.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 13</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch13_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<H1 CLASS=chapter><A CLASS="TITLE" NAME="JAWT-CH-13">13. AWT Exceptions and Errors</A></H1>

<DIV CLASS=htmltoc>

<p>
<b>Contents:</b><br>
AWTException<br>
<A HREF="ch13_02.htm">IllegalComponentStateException</A><BR>
<A HREF="ch13_03.htm">AWTError</A><BR>

<p>
</DIV>

<P CLASS=para>
This chapter describes <tt CLASS=literal>AWTException</tt>, 
<tt CLASS=literal>IllegalComponentStateException</tt>, 
and <tt CLASS=literal>AWTError</tt>. <tt CLASS=literal>AWTException</tt> 
is a subclass of <tt CLASS=literal>Exception</tt>. 
It is not used by any of the public classes in <tt CLASS=literal>java.awt</tt>; 
you may, however, find it convenient to throw <tt CLASS=literal>AWTException</tt> 
within your own code. <tt CLASS=literal>IllegalComponentStateException</tt> 
is another <tt CLASS=literal>Exception</tt> subclass, 
which is new to Java 1.1. This exception is used when you try to do something 
with a <tt CLASS=literal>Component</tt> that is not 
yet appropriate. <tt CLASS=literal>AWTError</tt> is 
a subclass of <tt CLASS=literal>Error</tt> that is 
thrown when a serious problem occurs in AWT--for example, the environment 
is unable to get the platform's <tt CLASS=literal>Toolkit</tt>. <A NAME="CH13.ERROR1"></A>

<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JAWT-CH-13-SECT-1">13.1 AWTException</A></h2>

<P CLASS=para>
<tt CLASS=literal>AWTException</tt> is a generic exception 
that can be thrown when an exceptional condition has occurred within AWT. 
None of the AWT classes throw this. If you subclass any of the AWT classes, 
you can throw an <tt CLASS=literal>AWTException</tt> 
to indicate a problem. Using <tt CLASS=literal>AWTException</tt> 
is slightly preferable to creating your own <tt CLASS=literal>Exception</tt> 
subclass because you do not have to generate another class file. Since it is a part of Java, <tt CLASS=literal>AWTException</tt> 
is guaranteed to exist on the run-time platform. 

<P CLASS=para>
If 
you throw an instance of <tt CLASS=literal>AWTException</tt>, like any other <tt CLASS=literal>Exception</tt>,
it must be caught in a <tt CLASS=literal>catch</tt> clause 
or declared in the <tt CLASS=literal>throws</tt> clause 
of the method. 

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JAWT-CH-13-SECT-1.1">AWTException Method</A></h3>Constructor

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>public AWTException (String message) </I><br>
<DD>

<P CLASS=para>
The sole constructor creates an <tt CLASS=literal>AWTException</tt> 
with a detailed message of <tt CLASS=literal>message</tt>. 
This message can be retrieved using <tt CLASS=literal>getMessage()</tt>, 
which it inherits from <tt CLASS=literal>Exception</tt> 
(and which is required by the <tt CLASS=literal>Throwable</tt> 
interface). If you do not want a detailed message, <tt CLASS=literal>message</tt> may be <tt CLASS=literal>null</tt>. </DL>
</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JAWT-CH-13-SECT-1.2">Throwing an AWTException</A></h3>

<P CLASS=para>
An <tt CLASS=literal>AWTException</tt> is used the 
same way as any other <tt CLASS=literal>Throwable</tt> 
object. Here's an example: 

<DIV CLASS=screen>
<P>
<PRE>
if (someProblem) {
    throw new AWTException ("Problem Encountered While Initializing");
}
</PRE>
</DIV>

</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch12_05.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch13_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>ImageFilter</td>
<td width=171 align=center valign=top><a href="index/idx_a.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>IllegalComponentStateException</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
